package com.ss.android.article.base.feature.detail.view;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.a.c.ThemedCommentDialog;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.video.DialogShowHelper;
import com.ss.android.article.base.ui.ImeFrameLayout;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;

import org.json.JSONObject;

public final class DetailCommentDialog extends ThemedCommentDialog implements ImeFrameLayout.OnImeEventListener {
    private AppData mAppData;
    private Activity mActivity;
    private ImeFrameLayout mImeFrameLayout;
    private String mArticleCommentTooLongTips;
    private CheckBox mCheckBox;
    private TextView mTextView;
    private boolean H;
    private JSONObject I;

    public DetailCommentDialog(Activity activity) {
        super(activity);
        this.H = true;
        this.mAppData = AppData.getInstance();
        this.mActivity = activity;
        this.mArticleCommentMaxTextLength = this.mAppData.articleCommentMaxTextLength;
        this.mArticleCommentTooLongTips = this.mAppData.articleCommentTooLongTips;
        if (android.support.design.a.isTextEmpty(this.mArticleCommentTooLongTips)) {
            this.mArticleCommentTooLongTips = activity.getString(com.ss.android.article.browser.R.string.detail_comment_too_long);
        }
    }

    public final int getLayoutId() {
        return R.layout.dialog_detail_comment;
    }

    public final void dismiss() {
        super.dismiss();
        DialogShowHelper.getInst().removeDialog(this);
    }

    public final void e() {
        int v0 = this.mArticleCommentMaxTextLength - this.mShareText.getText().length();
        if (v0 < 0) {
            this.mLimitText.setVisibility(View.VISIBLE);
            this.mLimitText.setText(String.valueOf(v0));
        } else {
            this.mLimitText.setVisibility(View.GONE);
        }
    }

    public final void f() {
        if (this.mShareText.getText().toString().trim().length() > this.mArticleCommentMaxTextLength) {
            UIUtils.showImageToast(this.mContext, R.drawable.close_popup_textpage, this.mArticleCommentTooLongTips);
        } else {
            this.v = this.mCheckBox.getVisibility() == View.VISIBLE && this.mCheckBox.isChecked();
            super.f();
        }
    }

    public final void g() {
        super.g();
        Resources v0 = this.getContext().getResources();
        UIUtils.setMaxLines(this.mTextView, R.drawable.cc);
        this.mTextView.setTextColor(v0.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi7));
        this.mShareText.setHintTextColor(v0.getColor(com.ss.android.article.browser.R.color.cg));
        this.mShareText.setTextColor(v0.getColor(com.ss.android.article.browser.R.color.ssxinzi1));
        UIUtils.setBackgroundResource(this.A, R.drawable.dk);
        this.mCheckBox.setTextColor(this.getContext().getResources().getColorStateList(com.ss.android.article.browser.R.color.yp));
        this.mCheckBox.setCompoundDrawablesWithIntrinsicBounds(this.getContext().getResources().getDrawable(com.ss.android.article.browser.R.drawable.dw), null, null, null);
        this.z.setBackgroundResource(com.ss.android.article.browser.R.color.ssxinmian3);
    }

    final void h() {
        this.mTextView.setEnabled(this.mShareText.getText().toString().trim().length() > 0);
    }

    public final void i() {
        if (this.isShowing()) {
            this.dismiss();
        }
    }

    private JSONObject j() {
        if (this.I == null) {
            this.I = new JSONObject();
        }
        try {
            this.I.put("forum_id", 0);
        } catch (Exception exception) {
        }

        return this.I;
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.getWindow().setBackgroundDrawableResource(com.ss.android.article.browser.R.drawable.e);
        this.getWindow().setLayout(-1, -2);
        this.getWindow().setGravity(80);
        this.f = false;
        this.mImeFrameLayout = this.findViewById(com.ss.android.article.browser.R.id.lc);
        this.mImeFrameLayout.setOnImeEventListener(((ImeFrameLayout.OnImeEventListener) this));
        this.mCheckBox = this.findViewById(com.ss.android.article.browser.R.id.lh);
        this.mTextView = this.findViewById(com.ss.android.article.browser.R.id.li);
        AppData.getInstance();
        AppData.isNightMode();
        UIUtils.setBackgroundResource(this.mTextView, R.drawable.cc);
        this.mTextView.setTextColor(this.getContext().getResources().getColorStateList(com.ss.android.article.browser.R.color.y1));
        this.mTextView.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View view) {
                DetailCommentDialog.this.f();
            }
        });
        this.mShareText.addTextChangedListener(new TextWatcher() {

            public final void afterTextChanged(Editable arg2) {
                DetailCommentDialog.this.h();
            }

            public final void beforeTextChanged(CharSequence arg1, int arg2, int arg3, int arg4) {
            }

            public final void onTextChanged(CharSequence arg1, int arg2, int arg3, int arg4) {
            }
        });
        this.h();
    }

    public final void onWindowFocusChanged(boolean hasFocus) {
        if ((hasFocus) && !this.H) {
            if (this.mActivity != null && this.p != null) {
                MobClickCombiner.onEvent(this.mActivity, "comment_add_topic", "cancel", 0, this.p.groupId, this.j());
            }
            this.H = true;
        }
        super.onWindowFocusChanged(hasFocus);
    }

    public final void show() {
        super.show();
        DialogShowHelper.getInst().addDialog(this);
        this.mCheckBox.setChecked(false);
        this.mCheckBox.setVisibility(View.GONE);
    }
}

